#include<bits/stdc++.h>
#define int long long 
#define rep_(i, a, b) for (int i = (a); i <= (b); i++)
using namespace std;
const int maxn = 3e5 + 10;
int n;
int a[maxn];
int dp[2005][2005][2];
void solve() {
	cin >> n;
	// if (n > 2000) exit(0);
	rep_(i, 0, n) rep_(j, 0, n) dp[i][j][0] = dp[i][j][1] = 0; 
	rep_(i, 1, n) {
		cin >> a[i];
	}
	rep_(i, 1, n){
		rep_(j, 0, 1) {
			rep_(k, 0, 1) {
				if (j == k) {
					rep_(g, 0, i - 2) {
						dp[i][g][j] = max(dp[i][g][j], dp[i - 1][g][j] + (a[i] == a[i - 1]) * a[i]);
					}
				} else {
					rep_(g, 0, i - 2) {
						dp[i][i - 1][j] = max(dp[i][i - 1][j], dp[i - 1][g][k] + (a[i] == a[g]) * a[i]);
					}
				}
			}
		}
	}
	int ans = 0;
	rep_(i, 0, n) {
		ans = max(ans, dp[n][i][0]);
		ans = max(ans, dp[n][i][1]);
	}
	cout << ans << endl;
}
signed main() {
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int t;
	cin >> t;
	rep_(i, 1, t) {
		solve();
	}
	return 0;
}